package com.store.app.adapter;

import android.content.Context;
import android.graphics.Color;
import android.text.Html;
import android.text.TextUtils;
import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.store.app.R;
import com.store.app.bean.OneYuanBuyDetailsBean;

import java.util.List;

public class OneYuanBuyDetailsAdapter extends BaseAdapter {
    private List<OneYuanBuyDetailsBean> goodsList;
    private Context context;
    private String luckNo;
    private long total = 0;
    private String status;

    public OneYuanBuyDetailsAdapter(List<OneYuanBuyDetailsBean> goodsList, Context context, String status) {
        this.goodsList = goodsList;
        this.context = context;
        this.status = status;
    }

//    public void setLuckNo(String luckNo, String total) {
//        if (!TextUtils.isEmpty(luckNo))
//            this.luckNo = luckNo;
//        this.total = Long.valueOf(total);
//    }

    @Override
    public int getCount() {
        int size = goodsList.size();
        return size;

    }

    @Override
    public Object getItem(int position) {

        return goodsList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_oneyuanbuy_details, null);
            viewHolder.goods_time = (TextView) convertView.findViewById(R.id.oyb_item_details_time);
            viewHolder.name = (TextView) convertView.findViewById(R.id.oyb_item_details_name);
            viewHolder.tv_state = (TextView) convertView.findViewById(R.id.tv_state);
            viewHolder.linearLayout = (LinearLayout) convertView.findViewById(R.id.layout_right);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }




        viewHolder.linearLayout.setVisibility(View.VISIBLE);
        Log.v("zyl", position + "：" + goodsList.get(position).getNick_name());

        OneYuanBuyDetailsBean buyDetailsBean = goodsList.get(position);




        String status =buyDetailsBean.getStatus();

        String s_goods_time = buyDetailsBean.getCreated_date().substring(0, 10) + "\n" + buyDetailsBean.getCreated_date().substring(11, buyDetailsBean.getCreated_date().length());
        if (!TextUtils.isEmpty(s_goods_time)) {
            viewHolder.goods_time.setText(s_goods_time);
        }
        viewHolder.tv_state.setVisibility(View.VISIBLE);
        //已兑奖
        if(status.equals("exchanged")){
            viewHolder.tv_state.setText("已兑奖");
            viewHolder.tv_state.setBackgroundResource(R.drawable.border_gray_empty_999999);
            viewHolder.name.setTextColor(Color.parseColor("#fe6d34"));
            viewHolder.tv_state.setTextColor(Color.parseColor("#999999"));
        }
        //未兑奖
        else if(status.equals("win")){
            viewHolder.tv_state.setText("未兑奖");
            viewHolder.tv_state.setBackgroundResource(R.drawable.border_gray_empty_f36d34);
            viewHolder.name.setTextColor(Color.parseColor("#fe6d34"));
            viewHolder.tv_state.setTextColor(Color.parseColor("#fe6d34"));
        }else{
            viewHolder.tv_state.setVisibility(View.GONE);
            viewHolder.name.setTextColor(Color.parseColor("#666666"));
        }
        if (TextUtils.isEmpty(buyDetailsBean.getNick_name())) {
            viewHolder.name.setText(buyDetailsBean.getMobile());
        } else {
            viewHolder.name.setText(buyDetailsBean.getMobile() + " (" + buyDetailsBean.getNick_name().trim() + ")");
        }

        viewHolder.goods_time.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
        return convertView;
    }


    class ViewHolder {
        private TextView goods_time;
        private TextView name;
        private TextView tv_state;
        private LinearLayout linearLayout;
    }


}
